<template>
	<view class="">
		<view class="floating">
			<view class="characters">{{info.title}}</view>
			<view class="floating_left">
				<view>销售订单：{{total.pre_sell_count ? total.pre_sell_count : '0' }}</view>
				<view>积累佣金：{{centsToYuan(total.pre_sell_comm ? total.pre_sell_comm : '0' )}}</view>
				<view>已结算佣金：{{centsToYuan(total.sell_comm ? total.sell_comm : '0' )}}</view>
			</view>
			<view class="floating_right">
				<view>销售金额：{{centsToYuan(total.pre_sell_amount ? total.pre_sell_amount : '0' )}}</view>
				<view></view>
				<view>待结算佣金：{{centsToYuan(total.pre_sell_comm - total.sell_comm)}}</view>
			</view>
		</view>
		<view class="istarted_neirong">
			<view class="tuiTips" style="margin-top: 40%;" v-if="rareData.length == 0" >
				<tui-tips :fixed="false" imgUrl="/static/toast/img_nodata.png">暂时还没有内容</tui-tips>
			</view>
			<view v-if="rareData" class="istarted" v-for="(item, index) in rareData" :key="index">
				<view class="istarted_top">
					<view class="istarted_top_left">订单号：{{item.order_sn}}</view>
					<view class="istarted_top_right" :style="item.settle_status == 2? 'color:#73CD11;': 'color:#F51C36;'">{{item.settle_status == 2? '已结算': '待结算'}}</view>
				</view>
				<view>
					<block v-for="(goodsList_item,goodsList_index) in item['goods_info']" :key="index">
						<tui-list-cell padding="0">
							<view class="tui-goods-item">
								<!-- <image src="/static/my/bg.png" class="tui-goods-img"></image> -->
								<view class="tui-goods-center">
									<view class="tui-goods-name">{{goodsList_item.goods_name}}</view>
									<view class="tui-goods-name">【{{goodsList_item.goods_attr}}】 +{{goodsList_item.goods_number}}</view>
								</view>
								<view class="tui-price-right">
									<view>￥{{centsToYuan(goodsList_item.goods_price * goodsList_item.goods_number)}}</view>
								</view>
							</view>
						</tui-list-cell>
					</block>
				</view>
				<view class="istarted_pay">
					<view class="istarted_pay_left">
						<view class="istarted_pay_top">下单用户</view>
						<view class="istarted_pay_user">
							<image :src="item.imageurl"></image>
							{{item.nickname}}
						</view>
					</view>
					<view class="istarted_pay_left">
						<view class="istarted_pay_top">支付金额</view>
						<view class="istarted_pay_bottom">
							¥ {{centsToYuan(item.amount)}}
						</view>
					</view>
					<view class="istarted_pay_left">
						<view class="istarted_pay_top">{{item.settle_status == 2? '结算佣金': '预估佣金'}}</view>
						<view class="istarted_pay_bottom">
							¥ {{centsToYuan(item.sell_profit)}}
						</view>
					</view>
				</view>
				<view class="istarted_bottom">
					<view class="istarted_bottom_left">{{formatDate(item.pay_time)}}付款</view>
					<view class="istarted_bottom_right">{{formatDate(item.sell_settle_time)}}结算</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const dataTime = require('../../utils/util.js');

	import tuiListView from "@/components/list-view/list-view"
	import tuiListCell from "@/components/list-cell/list-cell"
	import tuiIcon from "@/components/icon/icon"
	import tuiTag from "@/components/tag/tag"
	import tuiCard from "@/components/card/card"
	import tuiToast from "@/components/extend/toast/toast"
	import tuiTips from "@/components/extend/tips/tips"
	
	export default {
		components: {
			tuiIcon,
			tuiTag,
			tuiListView,
			tuiListCell,
			tuiCard,
			tuiToast,
			tuiTips
		},
		data() {
			return {
				userInfo: '',
				rareData: [],
				page: 1,
				loadding: false,
				pullUpOn: true,
				empty: 1,
				scrollTop: 0,
				istarted: [],
				jielong_id: '',
				info: '',
				total: ''
			}
		},
		onLoad:function(option){
			this.jielong_id = option.id;
			console.log('id',this.jielong_id);
			this.userInfo = uni.getStorageSync('userInfo');
			if(this.userInfo){
				this.loadData();
			}else{
				this.empty = 0
				this.loadding = false
				this.pullUpOn = false
			}
			
		},
		methods: {
			centsToYuan: function(amount){
				return this.tui.centsToYuan(amount);
			},
			loadData: function(){
				this.loadding = true
				var array = {jielong_id: this.jielong_id,page_size: 5 ,page: this.page};
				this.tui.request('user/shareSellOrder',array).then((res) => {
					console.log(res)
					this.info = res.info;
					this.total = res.total;
					if(res.list.list.length > 0){
						this.loadding = false
						this.pullUpOn = true
						this.empty = 1
						this.page++
						for( let i = 0; i < res.list.list.length; i++ ){
							res.list.list[i]['goods_info'] = JSON.parse(res.list.list[i]['goods_info']);
							this.rareData.push(res.list.list[i])
						}
						console.log(this.rareData);
					}else{
						this.loadding = false
						this.pullUpOn = false
					}
					if(res.list.list.length == 0 &&  this.page == 1){
						this.empty = 0
					
					}
				}).catch((err) => {
					let params = {
						title: "服务器异常",
						imgUrl: "/static/toast/fail-circle.png",
						icon: true
					};
					this.$refs.toast.show(params);
				})
			},
			formatDate: function (timestamp) {
				// return dataTime.getDateDiff(timestamp);
				return dataTime.formatDate('y-m-d h-i',timestamp)
			},
			formatDatetime: function (timestamp) {
				// return {text: dataTime.getDateDiff(timestamp)}
				var timestamp = dataTime.getDateDiff(timestamp);
				return timestamp;
			},
			price: function(amount){
				return '￥' + this.tui.centsToYuan(amount).toFixed(2);
			},
			wxGetUserInfo: function() {
				let that = this;
				that.tui.wxLogin().then((res)=>{
					if(res.code == '0000'){
						that.userInfo = res;
						this.loadData();
					}
				});
			},
		},
		onPullDownRefresh: function() {
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 200);
		},
		onReachBottom: function() {
			console.log('下拉事件');
			if(this.pullUpOn == true){
				this.loadData();
			}
		},
		onPageScroll: function(e) {
			this.scrollTop = e.scrollTop;
		},
		disMove:function(){
		 
		},
	}
</script>

<style>
	.floating{
		width: 86%;
		height: 240rpx;
		background: #FFF;
		padding-left: 7%;
		position: fixed;
		top: 0;
		padding-right: 7%;
		padding-top: 2%;
		padding-bottom: 2%;
		border-bottom: 20rpx solid #f5f6f8;
		z-index: 9999;
	}
	
	.characters{
		font-size: 36rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		line-clamp: 1;
		-webkit-box-orient: vertical;
	}
	
	.floating_left{
		width: 50%;
		float: left;
	}
	
	.floating_right{
		width: 50%;
		float: right;
	}
	
	.floating_left view{
		margin-top: 22rpx;
		font-size: 28rpx;
		color: #999;
		height: 35rpx;
	}
	
	.floating_right view{
		margin-top: 22rpx;
		font-size: 28rpx;
		color: #999;
		height: 35rpx;
	}
	
	.istarted_neirong{
		margin-top:320rpx;
	}
	
	.istarted{
		background: #FFF;
		/* margin-bottom: 40rpx; */
		padding: 20rpx;
		width: 90%;
		margin: 0 auto 20rpx;
		border-radius: 4rpx;
	}
	
	.istarted_top{
		width: 100%;
		height: 44rpx;
		font-size: 28rpx;
	}
	
	.istarted_top_left{
		width: 80%;
		float: left;
		color: #999;
	}
	
	.istarted_top_right{
		width: 20%;
		float: right;
		text-align: right;
	}
	
	.istarted_bottom{
		width: 100%;
		color: #999;
		font-size: 26rpx;
		line-height: 40rpx;
		height: 40rpx;
	}
	
	.istarted_bottom_left{
		width: 50%;
		float: left;
	}
	
	.istarted_bottom_right{
		width: 50%;
		float: right;
		text-align: right;
	}
	
	.istarted_pay{
		width: 100%;
		height: 130rpx;
		font-size: 26rpx;
		padding-top: 20rpx;
		border-top: 2rpx solid #EEEEEE;
	}
	
	.istarted_pay_left{
		width: 33%;
		float: left;
	}
	
	.istarted_pay_bottom{
		line-height: 70rpx;
	}
	
	.istarted_pay_user{
		line-height: 70rpx;
	}
	
	.istarted_pay_user image{
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		float: left;
		margin-top: 6rpx;
		margin-right: 12rpx;
	}
	
	.tui-goods-item {
		width: 100%;
		padding: 0rpx 20rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
	}
	
	.tui-goods-img {
		width: 180rpx;
		height: 180rpx;
		display: block;
		flex-shrink: 0;
	}
	
	.tui-goods-center {
		flex: 1;
		padding: 20rpx 8rpx;
		box-sizing: border-box;
	}
	
	.tui-goods-name {
		/* max-width: 450rpx; */
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		font-size: 28rpx;
		line-height: 34rpx;
		color: #666;
		float: left;
	}
	
	.tui-goods-attr {
		font-size: 22rpx;
		color: #888888;
		line-height: 32rpx;
		padding-top: 20rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}
	
	.tui-price-right {
		text-align: right;
		font-size: 28rpx;
		color: #888888;
		line-height: 30rpx;
		padding-top: 20rpx;
	}
</style>
